﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class ResourceLoadConfig : MonoBehaviour {

	static readonly string key = "ResourceLoadTypeKey";

	[MenuItem("Kylin/设置资源加载方式/AssetBundle")]
	public static void UseAssetBundle() {
		PlayerPrefs.SetString (key, "AssetBundle");
	}

	[MenuItem("Kylin/设置资源加载方式/AssetBundle", true)]
	public static bool UseAssetBundleValidate() {
        return IsUseResource();
	}

	[MenuItem("Kylin/设置资源加载方式/Resources")]
	public static void UseAssetResources() {
        SetUseResource();
	}

	[MenuItem("Kylin/设置资源加载方式/Resources", true)]
	public static bool UseAssetResourcesValidate() {
        return IsUseAssetBundle();
	}

    public static void SetUseResource()
    {
        PlayerPrefs.SetString(key, "Resources");
    }

    public static void SetUseAssetBundle()
    {
        PlayerPrefs.SetString(key, "AssetBundle");
    }

    public static bool IsUseResource()
    {
        if (PlayerPrefs.GetString(key) == "Resources")
        {
            return true;
        }
        return false;
    }

    public static bool IsUseAssetBundle()
    {
        if (PlayerPrefs.GetString(key) != "Resources")
        {
            return true;
        }
        return false;
    }
}

[InitializeOnLoad]
public class EditorStartup
{
	public static readonly string ResourceLoadTypeKey = "ResourceLoadTypeKey";
	static EditorStartup()
	{
		if (PlayerPrefs.GetString(ResourceLoadTypeKey, "default") == "default")
		{
			PlayerPrefs.SetString(ResourceLoadTypeKey, "Resources");
		}
		else
        {
			Debug.Log("ResourceLoadTypeKey this time is: " + PlayerPrefs.GetString(ResourceLoadTypeKey));
        }
	}
}
